package com.nlp.trie.array.trie;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.nlp.trie.bigramSeg.TernarySearchTrie;

public class Test {
	
	public static void main(String[] args) {
		try {
			
			int a = 5;
			//int b = a * 2;  相当于 int b = a << 1;
			//int b = a * 2;
			int b = a << 2;
			System.out.println(b);
			System.out.println("****************");
			InputStream file = TernarySearchTrie.class.getResourceAsStream("/small");
			BufferedReader reader = new BufferedReader(new InputStreamReader(file, "UTF-8"));
			String line;
			List<String> 	words = new ArrayList<>();
			Set<Character> charset = new HashSet<>();
			while ((line = reader.readLine()) != null) {
				words.add(line);
				for (char c : line.toCharArray()) {
					charset.add(c);
				}
			}
			reader.close();
			
			//这个字典如果要加入新词必须按字典顺序，参考下面的代码
//			Collections.sort(words);
//			BufferedWriter writer = new BufferedWriter(new FileWriter("./data/sorted.dic", false));
//			for (String w : words) {
//				writer.write(w);
//				writer.newLine();
//			}
//			writer.close();
			
			System.out.println("字典词条："+words.size());
			{
				String infoCharsetValue = "";
				String infoCharsetCode = "";
				for (Character c : charset) {
					infoCharsetValue += c.charValue() +"	";
					infoCharsetCode += (int)c.charValue() + " ";
				}
				infoCharsetValue += '\n';
				infoCharsetCode += '\n';
				System.out.println(infoCharsetValue);
				System.out.println(infoCharsetCode);
			}
			
			DoubleArrayTrie dat = new DoubleArrayTrie();
			System.out.println("是否错误：" + dat.build(words));
			System.out.println(dat);
			List<Integer> integers = dat.commonPrefixSearch("一举成名天下知");
			for (Integer index : integers) {
				System.out.println(words.get(index));
			}
			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
